package com.yy.chapter7.controlleradvice;

import com.yy.chapter7.exception.MyException;
import com.yy.chapter7.vo.ResponseVo;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author yangyao
 * @Description: 统一异常处理
 * @date 2018/10/24 09:29
 */
@RestControllerAdvice
public class GolbalExceptionHandler {

    @ExceptionHandler(value = MyException.class)
    @ResponseStatus(value = HttpStatus.OK)
    public ResponseVo handlerException(Exception e){
        return new ResponseVo(100,e.getMessage());
    }

    @ExceptionHandler(value = Exception.class)
    @ResponseStatus
    public ResponseVo handlerGolbalException(Exception e){
        return new ResponseVo(9999,"未知异常");
    }
}
